import {
  productDetailNew
} from '../../../api.js'
let app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    indicatorDots: false,
    autoplay: true,
    interval: 5000,
    duration: 200,
    imgUrls: [],
    imgUrls_length: 0,
    imgUrls_num: 1,
    value: '',
    full_name: '',
    business_name: '',
    peer_price: '',
    synopsis: '',
    buyImmediately: [],
    goodes_id: '',
    is_synchronize: 0,
    product_sn: '',
    EitiLis: {},
    price:''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    console.log(options.id)
    console.log(options.is_synchronize)
    var that = this;
    productDetailNew({
      token: app.globalData.userInfo.token,
      id: options.id
    }).then(res => {
      console.log(res)
      that.setData({
        EitiLis: res.data.data,
        value: res.data.data.finess_value,
        full_name: res.data.data.full_name,
        business_name: res.data.data.business_name,
        peer_price: res.data.data.peer_price,
        price: res.data.data.price,
        imgUrls: res.data.data.image,
        synopsis: res.data.data.synopsis,
        imgUrls_length: res.data.data.image.length,
        goodes_id: res.data.data.id,
        is_synchronize: options.is_synchronize,
        buyImmediately: {
          full_name: res.data.data.full_name,
          peer_price: res.data.data.peer_price,
          price: res.data.data.price,
          pic: res.data.data.image[0].pic_url,
          id: res.data.data.id,
          business_country: res.data.data.business_country
        },
        product_sn: res.data.data.product_sn
      })
      if (res.data.code == 111111) {
        wx.showToast({
          title: '登录失效，请重新登录',
          icon: 'none',
        })
        setTimeout(function () {
          wx.reLaunch({
            url: '/pages/user/login/login',
          })
        }, 1500)
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
  bindchange: function (e) {
    var num = e.detail.current;
    var that = this;
    that.setData({
      imgUrls_num: num + 1
    })
  },
  foter_btn_x: function () {
    wx.navigateBack({
      delta: 1
    })
  },
  foter_btn_q: function () {
    let keyArr = Object.keys(this.data.buyImmediately)
    let map = Object.create(null)
    let k;
    for (let i = 0, l = keyArr.length; i < l; i++) {
      k = keyArr[i]
      map[k] = encodeURIComponent(this.data.buyImmediately[k])
    }
    wx.navigateTo({
      url: '/pages/public/confirmBuy/confirmBuy?product=' + JSON.stringify([map]),
    })
  },
  syncGoods(e) {
    let id = e.currentTarget.dataset.id;
    let types = e.currentTarget.dataset.types;
    wx.navigateTo({
      url: '/pages/goodControl/syncGoods/syncGoods?id=' + id + '&type=' + types,
    })
  },
})